﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Bank
    {
        List<Account> accounts = new List<Account>();
        Account account = new Account();

        public void AddAccount()
        {
            accounts.Add(account);
            int lastUsedId = 1;
            foreach (var acc in accounts)
            {
                lastUsedId= account.Id;
            }
            account.Id = lastUsedId++;
            Console.WriteLine("введите сумму");
            decimal money;
            bool result = Decimal.TryParse(Console.ReadLine(),out money);
            if (result) { account.Money = money; }
            else
            {
                Console.WriteLine("Введена некорректная сумма, счёт не открыт");
                DelAccount(lastUsedId++);
            }

        }

        public void DelAccount(int id)
        {
            int index = 0;
            foreach (var acc in accounts)
            {
                if (id == account.Id)
                index = accounts.IndexOf(account);
            }
            accounts.RemoveAt(index);
        }
        public void ShowAllAccounts()
        {
            foreach (var acc in accounts)
            { Console.WriteLine("{0} {1}", acc.Id, acc.Money); }
        }




    }
}

